#include "newstrayicon.hpp"
#include "newsviewer.hpp"
#include "newsfetcher.hpp"
#include <QApplication>
#include <QTextStream>
#include <QFile>
#include <QDialog>
#include <QDialogButtonBox>
#include <QPushButton>
#include <QVBoxLayout>
#include <QWebSettings>
#include <fstream>
#include <cstring>
using namespace std;
NewsTrayIcon::NewsTrayIcon():QSystemTrayIcon()
{
    newssetting = new NewsSetting();
    newsviewer = new NewsViewer(newssetting);
    setIcon(QIcon(":/pic/rss.png"));

    newsfetcher = new NewsFetcher("http://lecture.pku.edu.cn",
                                  ":/js/lecture.js",this);

    connect(newsfetcher,SIGNAL(finished(bool)),newsviewer,SLOT(readFile()));

    createContextMenu();
}

void NewsTrayIcon::createContextMenu()
{
    menu.addAction(QIcon(":/pic/rss.png"),tr("N&ewsViewer"),newsviewer,SLOT(show()));
    menu.addSeparator();
    menu.addAction(tr("S&etting"),newssetting,SLOT(show()));
    menu.addSeparator();
    menu.addAction(QIcon(":/pic/exit.png"),tr("E&xit"),qApp,SLOT(quit()));
    setContextMenu(&menu);
}
